﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace first_project
{
    class AsteroidManager
    {
        private Texture2D asteroidTexture;
        public List<Asteroid> asteroids;
        private float delay;
        private float lastTime;
        private GameWindow Window;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="delay">The time to create the asteroid</param>
        public AsteroidManager(Texture2D asteroidTexture, float delay, GameWindow Window)
        {
            this.delay = delay;
            lastTime = 0;
            this.asteroidTexture = asteroidTexture;
            this.Window = Window;
            this.asteroids = new List<Asteroid>();
        }

        private void createAsteroid()
        {
            Asteroid asteroid = new Asteroid(asteroidTexture, 4, Window);
            asteroids.Add(asteroid);
        }

        public void Update(GameTime gameTime)
        {
            if (gameTime.TotalGameTime.TotalMilliseconds >= lastTime + delay)
            {
                lastTime = (float)gameTime.TotalGameTime.TotalMilliseconds;
                createAsteroid();
            }

            foreach (Asteroid asteroid in asteroids)
            {
                asteroid.update(gameTime);
            }
             
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            foreach (Asteroid asteroid in asteroids)
            {
                asteroid.draw(spriteBatch);
            }
        }

    }
}
